Skip to content

Conversation

@jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented Oct 29, 2025

Adds support in crossgen2 for emitting Mach-O objects.

Does not yet do the runtime support as that depends on #120777

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkoritzinsky
Copy link
Member Author

/azp run runtime-ioslike

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).


<MakeDir Directories="$([System.IO.Path]::GetDirectoryName(%(_ReadyToRunNativeObjectOutputs.Identity)))" />

<Exec Command="&quot;$(_AppleClang)&quot; @(_MachLinkerArg, ' ')" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since -ld_classic results in a warning on Xcode 16+, I think we need to do something like:

IgnoreStandardErrorWarningFormat="$(_IgnoreLinkerWarnings)"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this still needs to be addressed. Also in crossgen-corelib.

@elinor-fung
Copy link
Member

I pulled this down to check out the generated System.Private.CoreLib.dylib built on a mac - targeted osx and ios. dyld_info works fine, otool shows the sections I'd expect, nm -u doesn't show any undefined (for ios, it does show dyld_stub_binder, which I think is fine/expected). For the osx one, I checked I could dlopen it successfully.

Copy link
Member

@elinor-fung elinor-fung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the comment about the linker warnings, looks good to me.

</Target>

<Target
Name="LinkCoreLibMachO"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse SetupOSSpecificProps target instead of duplication?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's difficult to reuse the NativeAOT targets here and we only need a stripped-down version of them, so it's easier to duplicate (especially as we the design for exactly how we want to produce the Mach-O files may change).

Copy link
Member

@elinor-fung elinor-fung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally for macos (osx, not mobile) with the runtime/host changes. With the fix for the flipped *_RELOC_SUBTRACTOR/*_RELOC_UNSIGNED index, I can successfully run a runtime test using the Mach-O R2R SPCL and a Mach-O R2R image for the test assembly itself.

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = startSymbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = startSymbolIndex,
SymbolOrSectionIndex = endSymbolIndex,

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = endSymbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = endSymbolIndex,
SymbolOrSectionIndex = startSymbolIndex,

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = (uint)symbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = (uint)symbolIndex,
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],
SymbolOrSectionIndex = (uint)symbolIndex,

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = startSymbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = startSymbolIndex,
SymbolOrSectionIndex = endSymbolIndex,

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = endSymbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = endSymbolIndex,
SymbolOrSectionIndex = startSymbolIndex,

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = (uint)symbolIndex,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SymbolOrSectionIndex = (uint)symbolIndex,
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],

new MachRelocation
{
Address = (int)symbolicRelocation.Offset,
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symbols are flipped - the pair represents <unsigned_symbol> - <subtractor_symbol>, so ARM64_RELOC_SUBTRACTOR should be the base.

Suggested change
SymbolOrSectionIndex = _symbolNameToIndex[_baseSymbolName],
SymbolOrSectionIndex = (uint)symbolIndex,

elinor-fung added a commit that referenced this pull request Nov 11, 2025
…composite R2R images (#121363)

Add the basic runtime flow for calling into the host to get information
about a platform-native R2R - see docs/design/coreclr/botr/readytorun-platform-native-envelope.md#runtime-consuming-a-platform-native-r2r-image.
- Add `get_native_code_data` callback to `host_runtime_contract`
- If a component R2R assembly has
`READYTORUN_FLAG_PLATFORM_NATIVE_IMAGE`, invoke the callback to get the
R2R header, image size, and image base address
- Currently only implemented and tested on Windows (with local changes
to include the flag)
- Mach-O support will need #121186

Contributes to #120065.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants